package com.hbzhit.modules.sys.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.hbzhit.common.enums.RoleOrgTypeEnum;
import com.hbzhit.common.utils.CacheUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * 角色
 *
 * @author Mark sunlightcs@gmail.com
 */
@Getter
@Setter
@TableName("sys_role")
public class SysRoleEntity implements Serializable {
	private static final long serialVersionUID = 1L;

	@ApiModelProperty("角色ID")
	@TableId
	private Long roleId;

	@ApiModelProperty("角色名称")
	@NotBlank(message="角色名称不能为空")
	private String roleName;

	@ApiModelProperty("备注")
	private String remark;

	@ApiModelProperty("角色组织权限类别")
	private Integer roleOrgType;

	@ApiModelProperty("创建人ID")
	private Long createUserId;

	@ApiModelProperty("创建时间")
	private Date createTime;

	@ApiModelProperty("菜单权限集合")
	@TableField(exist=false)
	private List<Long> menuIdList;

	@ApiModelProperty("组织权限集合")
	@TableField(exist=false)
	private List<Long> orgIdList;

	@ApiModelProperty("关联用户集合")
	@TableField(exist=false)
	private List<Long> userIdList;

	@ApiModelProperty("创建人名称")
	@TableField(exist = false)
	private String creatorName;

	@ApiModelProperty("角色组织权限类别名称")
	@TableField(exist = false)
	private String roleOrgTypeName;


	public String getCreatorName() {
		return CacheUtils.getUserCache(createUserId).getRealName();
	}

	public String getRoleOrgTypeName() {
		if (roleOrgType == null || RoleOrgTypeEnum.getEnum(roleOrgType) == null) {
			return null;
		}
		return Objects.requireNonNull(RoleOrgTypeEnum.getEnum(roleOrgType)).getName();
	}
}
